package cn.falcon.fmobi.console.requestparam;

import org.apache.commons.lang3.StringUtils;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 订单列表查询参数
 *
 * @author yujuan.zhang
 * @from 2017-10-17
 * @since V1.0
 */
public class CampaignQueryParam extends AbstractPagingSortParam {

    private String search;

    private Integer advertiserId;

    private Integer agentId;

    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date startDate;

    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date endDate;

    public String getSearch() {
        return search;
    }

    public void setSearch(String search) {
        this.search = search;
    }

    public Integer getAdvertiserId() {
        return advertiserId;
    }

    public void setAdvertiserId(Integer advertiserId) {
        this.advertiserId = advertiserId;
    }

    public Integer getAgentId() {
        return agentId;
    }

    public void setAgentId(Integer agentId) {
        this.agentId = agentId;
    }

    public Date getStartDate() {
        return startDate;
    }

    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }

    public Date getEndDate() {
        return endDate;
    }

    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }

    /**
     * 默认按id排序
     */
    @Override
    public String getSortby() {
        return StringUtils.isEmpty(super.getSortby()) ? "id" : super.getSortby();
    }

    /**
     * 默认按降序排序
     */
    @Override
    public ORDER getOrder() {
        return super.getOrder() == null ? ORDER.desc : super.getOrder();
    }

    public Map<String, Object> getSearchMap() {
        Map<String, Object> map = new HashMap<>();
        map.put("search", this.getSearch());
        map.put("sortby", this.getSortby());
        map.put("order", this.getOrder());
        map.put("advertiserId", advertiserId);
        map.put("agentId", agentId);
        return map;
    }
}
